import React,{Component} from 'react'

function IsLogin(Com){
    return class extends Component{
        state = {
            isLogin:false  //是否登录的状态
        }

        componentDidMount(){
            let token = localStorage.getItem('token');
            if(token){
                this.setState({
                    isLogin:true
                })
            }else{
                this.props.history.push('/login');
            }
        }

        render(){
            let {isLogin} = this.state;
            return isLogin ? <Com {...this.props}/> : <></>
        }
    }
}

export default IsLogin